package com.wisemoresystem.seal.action.config.macconfig;

import java.util.List;
import java.util.Map;

import org.ne.framework.data.util.ChkTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_paper;
import com.wisemoresystem.seal.service.MacConfigService;
import com.wisemoresystem.seal.service.PaperService;

@Controller("config")
@Scope("prototype")
@RequestMapping("/ix/config/paper")
/**
 * 印控仪纸张管理
 * @author Administrator
 *
 */
public class PapaerAction extends ProjBaseAction {
	@Autowired
	private PaperService paperservice;

	@Autowired
	private MacConfigService macconfigservic;

	/**
	 * 纸张列表
	 * 
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list() {

		List<Map<String, Object>> paperlist = paperservice.selectPaper();

		ModelAndView mv = new ModelAndView("jsp/config/paper/list");
		mv.addObject("paperlist", paperlist);
		return mv;

	}

	/**
	 * 纸张添加页面跳转
	 * 
	 * @return
	 */
	@RequestMapping("/add_form")
	public ModelAndView add_form() {

		ModelAndView mv = new ModelAndView("jsp/config/paper/add_form");

		return mv;

	}

	/**
	 * 之纸张添加
	 * 
	 * @param paper
	 *            纸张信息
	 * @return
	 */
	@RequestMapping("/add")
	public ModelAndView add(t_paper paper) {
		oc.saveObj(paper);
		logT.logH("添加设备配置纸张", t_paper.class, paper.get_id());
		ModelAndView mv = new ModelAndView("redirect:list.htm");

		return mv;

	}

	/**
	 * 去向纸张修改页面
	 * 
	 * @param paper_id
	 *            纸张id
	 * @return
	 */
	@RequestMapping("/edit_form")
	public ModelAndView edit_form(String paper_id) {

		t_paper paper = oc.findObjById(paper_id, t_paper.class);

		ModelAndView mv = new ModelAndView("jsp/config/paper/edit_form");
		mv.addObject("paper", paper);
		return mv;

	}

	/**
	 * 
	 * @param paper_id
	 *            纸张id
	 * @param paper
	 *            纸张信息
	 * @return
	 */
	@RequestMapping("/edit")
	public ModelAndView edit(String paper_id, t_paper paper) {
		t_paper paperDb = oc.findObjById(paper_id, t_paper.class);
		paperDb.setName(paper.getName());
		paperDb.setMac_config_id(paper.getMac_config_id());

		oc.updateObj(paperDb);
		logT.logH("修改设备配置纸张", t_paper.class, paperDb.get_id());
		ModelAndView mv = new ModelAndView("redirect:list.htm");

		return mv;

	}

	/**
	 * 删除纸张
	 * 
	 * @param paper_id
	 *            纸张id
	 * @return
	 */
	@RequestMapping("/del")
	public ModelAndView del(String paper_id) {

		List<Map<String, Object>> list = macconfigservic
				.selectMacConfigList(paper_id);

		if (ChkTools.isNull(list)) {
			oc.delObjById(paper_id, t_paper.class);
			super.setTipMsg("删除成功", Tip.Type.success);
			logT.logH("删除设备配置纸张", t_paper.class, paper_id);

		} else {
			super.setTipMsg("删除失败!该纸张有设备在用", Tip.Type.error);
		}
		;
		ModelAndView mv = new ModelAndView("redirect:list.htm");

		return mv;

	}

}
